package com.qpkj.web.controller.oms;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.qpkj.common.annotation.Log;
import com.qpkj.common.core.controller.BaseController;
import com.qpkj.common.core.domain.AjaxResult;
import com.qpkj.common.enums.BusinessType;
import com.qpkj.oms.domain.OmsTaskProduct;
import com.qpkj.oms.service.IOmsTaskProductService;
import com.qpkj.common.utils.poi.ExcelUtil;
import com.qpkj.common.core.page.TableDataInfo;

/**
 * 任务生产目标Controller
 *
 * @author ruoyi
 * @date 2022-12-20
 */
@RestController
@RequestMapping("/oms/taskproduct")
public class OmsTaskProductController extends BaseController {
    @Autowired
    private IOmsTaskProductService omsTaskProductService;
    /**
     * 根据任务id查询该任务生产所需
     *
     * @param taskId 任务ID
     * @return
     */
    @GetMapping(value = "/taskProductListByTaskId")
    public AjaxResult taskProductListByTaskId(@RequestParam("taskId") Long taskId) {
        List<OmsTaskProduct> list = omsTaskProductService.taskProductListByTaskId(taskId);
        return AjaxResult.success(list);
    }
    /**
     * 查询任务生产目标列表
     */
    @PreAuthorize("@ss.hasPermi('oms:taskproduct:list')")
    @GetMapping("/list")
    public TableDataInfo list(OmsTaskProduct omsTaskProduct) {
        startPage();
        List<OmsTaskProduct> list = omsTaskProductService.selectOmsTaskProductList(omsTaskProduct);
        return getDataTable(list);
    }

    /**
     * 导出任务生产目标列表
     */
    @PreAuthorize("@ss.hasPermi('oms:taskproduct:export')")
    @Log(title = "任务生产目标", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OmsTaskProduct omsTaskProduct) {
        List<OmsTaskProduct> list = omsTaskProductService.selectOmsTaskProductList(omsTaskProduct);
        ExcelUtil<OmsTaskProduct> util = new ExcelUtil<OmsTaskProduct>(OmsTaskProduct.class);
        util.exportExcel(response, list, "任务生产目标数据");
    }

    /**
     * 获取任务生产目标详细信息
     */
    @PreAuthorize("@ss.hasPermi('oms:taskproduct:query')")
    @GetMapping(value = "/{tpId}")
    public AjaxResult getInfo(@PathVariable("tpId") Long tpId) {
        return success(omsTaskProductService.selectOmsTaskProductByTpId(tpId));
    }

    /**
     * 新增任务生产目标
     */
    @PreAuthorize("@ss.hasPermi('oms:taskproduct:add')")
    @Log(title = "任务生产目标", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OmsTaskProduct omsTaskProduct) {
        return toAjax(omsTaskProductService.insertOmsTaskProduct(omsTaskProduct));
    }

    /**
     * 修改任务生产目标
     */
    @PreAuthorize("@ss.hasPermi('oms:taskproduct:edit')")
    @Log(title = "任务生产目标", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OmsTaskProduct omsTaskProduct) {
        return toAjax(omsTaskProductService.updateOmsTaskProduct(omsTaskProduct));
    }

    /**
     * 删除任务生产目标
     */
    @PreAuthorize("@ss.hasPermi('oms:taskproduct:remove')")
    @Log(title = "任务生产目标", businessType = BusinessType.DELETE)
    @DeleteMapping("/{tpIds}")
    public AjaxResult remove(@PathVariable Long[] tpIds) {
        return toAjax(omsTaskProductService.deleteOmsTaskProductByTpIds(tpIds));
    }
}
